<template>
  <div>
    <FormPanel  ref="formPanel"
        :list="initForm"   
        :cols="1"          
        :labelWidth="100"  
        :isSubmitBtn="false"  
        @formChange="formChangeHandle"
        class="mtop"
     />
     <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="sureDialog" type="primary">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
export default {
  mixins: [dictionary],
  data() {
    return {
      formData:[],
      initForm : this.initFormFun()
    };
  },
  mounted() {
    //如果传入参数不为空并且为修改
    if(this.value!=null && this.value.type=="edit"){
      this.init();
    }
  },
  
  methods: {
    //修改时，初始化页面数据
    init(){
      //初始化ID
      this.constructionId =  this.value.rowData.constructionId;
      //转换经销商类型
      let dt =  this.value.rowData.dealerTypeStr.split(',') ;
      for(let i in dt){
        dt[i] = parseInt(dt[i]);
      }
      this.value.rowData.dealerTypeList = dt;
      //循环为表单赋值
      this.initForm.forEach(x => {
        x.initialValue = this.value.rowData[x.fieldName];
      });

    },
    //搜索数据
    initFormFun(){
        return [
          { 
            type: 'TEXT_AREA', 
            label: '请填写审核意见', 
            fieldName: 'reason', 
            placeholder: '请输入', 
            initialValue: '' ,
            rules: [
              { max: 1000, 
                message: '长度最大1000字符', 
                trigger: 'blur' 
              }
            ]
          }
        ]
    },
    formChangeHandle(val){
      this.formData = val;
    },
    //确定
    sureDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      this.$emit('close', { visible: false ,"data":this.formData,"type":"sure"});
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false,"type":"close" });
    }
  },
}
</script>